package dao.impl;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;

import org.springframework.stereotype.Service;

import pojo.Customer;
import dao.CustomerDao;
@Service(value="customerDaoImpl2")
public class CustomerDaoImpl2 implements CustomerDao {
	@Resource(name="entityManager")
	private EntityManager manager;
	@Override
	public Customer addCustomer(Customer c) {
		EntityTransaction transaction = manager.getTransaction();
		transaction.begin();
		manager.persist(c);
		transaction.commit();
		return c;
	}

	@Override
	public Customer findCustomer(String cname, String psd) {
		
		Query query =  manager.createQuery("select c from Customer c where c.cname=?1 and c.password=?2 ");
		query.setParameter(1,cname);
		query.setParameter(2, psd);
		Customer customer = (Customer) query.getSingleResult();
		return customer;
	}

}
